class Solution {//leetcode1419——数青蛙
public:
    int minNumberOfFrogs(string croakOfFrogs) {
        int hash[5]={0};
        for(auto ch:croakOfFrogs){
            if(ch=='c'){
                hash[k]==0?0:hash[k]--;
                hash[c]++;
            }
            else{
                int i=0;
                switch(ch)
                {
                    case 'r':i=r;break;
                    case 'o':i=o;break;
                    case 'a':i=a;break;
                    case 'k':i=k;break;
                    default: return 0;
                }
                if(hash[i-1]==0) return -1;
                hash[i-1]--;
                hash[i]++;
            }
        }
        for(int i=0;i<k;i++) if(hash[i]!=0) return -1;
        return hash[k];
    }
private:
    const int c=0;
    const int r=1;
    const int o=2;
    const int a=3;
    const int k=4;
};